package com.petAdoption.manager.util;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.sql.DataSource;

//代码生成器
@Component
public class MyCodeGenerator {

    @Resource
    private DataSource dataSource;

    public void excute() {
        FastAutoGenerator.create(new DataSourceConfig.Builder(dataSource))
                .globalConfig(builder -> builder
                        .outputDir(System.getProperty("user.dir") + "/src/main/java")
                        .author("王倩茹")
                )
               //包参数配置
                .packageConfig(builder -> builder
                        .parent("com.petAdoption.manager")
                        .entity("entity")
                        .service("service")
                        .serviceImpl("service.impl")
                        .mapper("mapper")
                        .xml("mapper")
                        .controller("controller")
                )
                //模板配置
                // .templateConfig(builder -> builder
                // .entity()
                // .service()
                // .mapper()
                // .xml()
                // .controller()
                // )
                //策略配置
                // .strategyConfig(builder -> builder
                //
                // )
                //注入配置
                // .injectionConfig(builder -> builder
                // .build()
                // )
                //引擎
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
